<?php
//第一题
echo "(1)<br>";
class Good
{
	public $name;
	public $price;
	public $number;
	function __construct($n,$p,$nu)//构造函数，初始化对象
	{
		$this-> name = $n;
		$this-> price = $p;
		$this-> number = $nu;
	}
	function display()//显示商品信息
	{
		echo "商品信息<br>";
		echo "名称：".$this-> name."<br>";
		echo "价格：".$this-> price." 元<br>";
		echo "存量：".$this-> number." 件<br>";
	}
	function in($number,$in)//入库
	{
		$number=$number+$in;
		echo "入库信息<br>入库：".$in." 件<br>现存：".$number." 件";
		echo "<br>";
	}
	function out($number,$out)//卖出
	{
		$number=$number-$out;
		echo "卖出信息<br>卖出：".$out." 件<br>现存：".$number." 件";
		echo "<br>";
	}
}
$cloth = new Good("cloth",100,1000);
$cloth->display();
$cloth->in(1000,1000);
$cloth->out(2000,500);
echo "<br>";
//创建子类
class Shoes extends Good
{
	public $discountRate;
	public $discountPrice;
	function __construct($n,$p,$nu,$ra,$pr)//构造函数，初始化对象
	{
		$this-> discountRate = $ra;
		$this-> discountPrice = $pr;
		$this-> name = $n;
		$this-> price = $p;
		$this-> number = $nu;
	}
	function display()//显示
	{
		echo "商品信息2<br>";
		echo "名称：".$this-> name."<br>";
		echo "价格：".$this-> price."元<br>";
		echo "存量：".$this-> number."件<br>";
		echo "折扣率：".$this-> discountRate."<br>";
		echo "折扣价：".$this-> discountPrice."元<br>";
	}
}
$shoes = new Shoes("shoes",999,9999,0.3,699);
$shoes->display();


//第二题
echo "<br>(2)<br>";
class Fun
{
	function fun1(){
		echo "fun1"."<br>";
	}
	function fun2(){
		echo "fun2"."<br>";
	}
	function fun3(){
		echo "fun3"."<br>";
	}
	function fun4(){
		echo "fun4"."<br>";
	}
}
class MyFun extends Fun
{
	function fun1()
	{
		echo "自己写的功能<br>";
	}
	function fun2()
	{
		echo "fun2"."<br>";
		echo "增加一个功能<br>";
	}
	function fun3()
	{

	}//屏蔽fun3
}
$my =new MyFun();
$my->fun1();
$my->fun2();
$my->fun3();
$my->fun4();


//第三题
echo "<br>(3)<br>";
interface Shape
{
	public function area($x,$y,$r,$h);
	public function volume($v,$r,$h);
	public function display($x,$y,$r,$h);

}
class Point implements Shape
{
	public $x;
	public $y;
	function __construct($x,$y)
	{
		$this-> x = $x;
		$this-> y = $y;
	}
	function display($x,$y,$r,$h)
	{
		echo "x = ".$x;
		echo "<br>";
		echo "y = ".$y;
		echo "<br>";
	}
	function area($x,$y,$r,$h)
	{
		$a=$x*$y;
		if($a==0)
			return 0;
		else
			echo "area = ".$a."<br>";
	}
	function volume($v,$r,$h)
	{
		if($v==0)
			return 0;
		else
			echo "volume = ".$v."<br>";
	}
}
$point = new Point(0,0,0,0);
$point ->display(0,0,0,0);
$point ->area(0,0,0,0);
$point ->volume(0,0,0);
echo "<br>";

//第四题
echo "(4)<br>";
class Circle implements Shape
{
	public $r;
	function __construct($x,$y,$r)
	{
		$this-> r = $r;
	}
	function display($x,$y,$r,$h)
	{
		echo "r = ".$r;
		echo "<br>";

	}
	function area($x,$y,$r,$h)
	{
		$a=3.14*$r*$r;
		if($r==0)
			return 0;
		else
			echo "area = ".$a."<br>";
	}
	function volume($v,$r,$h)
	{
		$v=3.14*$r*$r*$r*4/3;
		if($v==0)
			return 0;
		else
			echo "volume = ".$v."<br>";
	}
}
$circle = new Circle(0,0,2,0);
$circle ->display(0,0,2,0);
$circle ->area(0,0,2,0);
$circle ->volume(0,2,0);
echo "<br>";

//第五题
echo "(5)<br>";
class Cylinder extends Circle
{
	public $h;
	function __construct($x,$y,$r,$h)
	{
		$this-> r = $r;
		$this-> h = $h;
	}
	function display($x,$y,$r,$h)
	{
		echo "r = ".$r;
		echo "<br>";
		echo "h = ".$h;
		echo "<br>";


	}
	function area($x,$y,$r,$h)
	{
		$a=3.14*$r*$r*2+3.14*2*$r*$h;
		if($r==0)
			return 0;
		else
			echo "area = ".$a."<br>";
	}
	function volume($v,$r,$h)
	{
		$v=3.14*$r*$r*$h;
		if($v==0)
			return 0;
		else
			echo "volume = ".$v."<br>";
	}
}
$cylinder = new Cylinder(0,0,2,0);
$cylinder ->display(0,0,2,5);
$cylinder ->area(0,0,2,5);
$cylinder ->volume(0,2,5);
echo "<br>";

?>